import { message } from 'antd';

// 判断该用户是否有权限
export const havePermissions = (buttonType: string, buttonPermissions: any) => {
  const hasSave =
    buttonPermissions?.filter((item: any) => item.menuCode === buttonType)?.length > 0;
  if (!hasSave) {
    message.info('请联系管理员获取相关权限');
    return false;
  } else {
    return true;
  }
};

export const downFile = (fileUrl: any, fileName = '未命名') => {
  if (!fileUrl) return;
  const link = document.createElement('a');
  link.href = fileUrl;
  link.download = fileName || 'download'; // 文件名可选，默认值可自定义
  document.body.appendChild(link);
  link.click(); // 直接触发点击，无需手动创建事件
  document.body.removeChild(link);
};
